<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 

<?php
	include("/../data.php");
	
	
	session_start();
	$_SESSION['db_is_logged_in'] = false;
	$remember=false;
	if(isset($_POST['ok']))
	{
	 
		if(($_POST['username'] == NULL)&&($_POST['password'] == NULL)) 
		{       
			echo "Please enter your username & password" ."<br>";
			//header("location:index.php");
		} 
		else if($_POST['username'] == NULL){           
			echo "Please enter your username" ."<br>";
			 //header("location:index.php"); 
		} 
		else if($_POST['password'] == NULL){         
				  echo "Please enter your password" ."<br>";
			 //header("location:index.php");                       
		} 
		else {
			$u=$_POST['username'];
			$p=md5( addslashes($_POST['password']));   
			$connect=mysql_connect($DatabaseServer,$DatabaseUsername,$DatabasePassword) or die("can't connect this database");
			mysql_select_db($DatabaseName,$connect);
			$sql="select * from staff where username='".$u."' and password='".$p."'";
			$query=mysql_query($sql);
			if(mysql_num_rows($query)==0) {
				
				echo "
				<div class='container'>
				  <form class='form-signin' role='form'>
					<h5 color='red' align='center' class='form-signin-heading'><font color='red'>Username or password is not correct, please try again</font></h5>				
				  </form>

				</div> <!-- /container -->
				";
				
				
				
				//header("location:index.php");     
			} 
			else{       
				$row=mysql_fetch_array($query);       
				$_SESSION['db_is_logged_in'] = true;     
				$_SESSION['username'] = $row["username"];
				$_SESSION['profile'] = $row["profile"];
				$_SESSION['password'] = $row["password"];
				
				/*			
				if (isset($_POST['remember'])) {
					$_SESSION['remember']=true;
					setcookie("remember", $_SESSION['remember'],time()+60*60*24*100);
					$_COOKIE["remember"];
					setcookie("InputUsername", $_SESSION['username'], time()+60*60*24*100, "/");
					$_COOKIE["InputUsername"];
					echo $_COOKIE["InputUsername"];
					setcookie("InputPassword", $_SESSION['password'], time()+60*60*24*100, "/");
					$_COOKIE["InputPassword"];                 
				}
				*/	
				header("location:menu.php"); // kiem tra dung, khong check 
				exit;       
			}
		} 
	}
	/* else //if($_COOKIE["remember"]==true) {
	 {
	 $_SESSION['db_is_logged_in'] = true;
	  //header("location:menu.php");
	  }
	*/
?>

<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="../../assets/ico/favicon.ico">
    <title>Signin Template for Bootstrap</title>

    <link href="css/bootstrap.min.css" rel="stylesheet">

    <link href="css/signin.css" rel="stylesheet">

  </head>

  <body>

    <div class="container">

      <form class="form-signin" role="form" action='index.php' method='POST'>
        <h2 class="form-signin-heading">Please sign in</h2>
        <input type="text" class="form-control" name='username' placeholder="Username" required autofocus>
        <input type="password" class="form-control" type='password' name='password' placeholder="Password" required>
        <label class="checkbox">
          <input type="checkbox" name="remember" value="remember-me"> Remember me
        </label>
        <button class="btn btn-lg btn-primary btn-block" name='ok' type="submit">Sign in</button>
      </form>

    </div> <!-- /container -->
  </body>
</html>
